﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Linq.SqlClient;
using System.Reflection;

namespace BussinesCosea
{
    public partial class CoseaDirectos : IDisposable
    {
        #region Métodos Privados

        private void CopyProperties(Object source, object target)
        {
            foreach (System.Reflection.PropertyInfo p in source.GetType().GetProperties())
            {
                PropertyInfo pTarget = target.GetType().GetProperty(p.Name);
                if (p == null) break;
                try { p.SetValue(target, p.GetValue(source, null), null); }
                catch { /*parece que aqui falla en algo...y creo que es en los nullables*/}
            }
        }

        private void CopyPropertiesSolicitud(Object source, object target)
        {
            foreach (System.Reflection.PropertyInfo p in source.GetType().GetProperties())
            {
                if (p.Name != "EmpleosSolicituds")
                {
                    if (p.Name != "HijosSolicituds")
                    {
                        if (p.Name != "Foto")
                        {
                            if (p.Name != "Preseleccions")
                            {
                                    PropertyInfo pTarget = target.GetType().GetProperty(p.Name);
                                    if (p == null) break;
                                    try { p.SetValue(target, p.GetValue(source, null), null); }
                                    catch { /*parece que aqui falla en algo...y creo que es en los nullables*/}                                
                            }
                        }
                    }
                }
            }
        }

        private void CopyPropertiesOrdenServicio(Object source, object target)
        {
            foreach (System.Reflection.PropertyInfo p in source.GetType().GetProperties())
            {
                if (p.Name != "ValesOrdenServicios")
                {
                    if (p.Name != "BonosOrdenServicios")
                    {
                        if (p.Name != "AsignacionOrdenServicios")
                        {
                            if (p.Name != "HistoriaOrdenServicios")
                            {
                                if (p.Name != "Preseleccions")
                                {
                                    PropertyInfo pTarget = target.GetType().GetProperty(p.Name);
                                    if (p == null) break;
                                    try { p.SetValue(target, p.GetValue(source, null), null); }
                                    catch { /*parece que aqui falla en algo...y creo que es en los nullables*/}
                                }
                            }
                        }
                    }
                }
            }
        }


        private int Folio()
        {
            int folio = 0;
            db = new bdCoseaDirectosDataContext(_cadenaConexion);
            foreach (ObtenFolioSolictudEmpleoResult item in db.ObtenFolioSolictudEmpleo())
            {
                folio = item.Column1.Value;
            }
            db = null;
            return folio;
        }

        #endregion
    }
}
